package com.gc.cscott.cli;

import com.gc.cscott.domain.Competitor;
import com.gc.cscott.domain.contest.Contest;
import com.gc.cscott.domain.contest.Source;
import com.gc.cscott.fs.FileSystemWorker;
import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
import com.google.inject.Injector;
import java.io.File;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author root
 */
public class ListCompetitorsCommand implements Command {
    @Inject
    Contest contest;

    @Inject
    FileSystemWorker fsWorker;

    public List<String> listHelp() {
        return Arrays.asList(
                "Here will be list of competitors");
    }

    public List<String> perform(List<String> pendingArgs) {
        System.out.println("Contest: " + contest.getName());
        System.out.println("Competitors list:");
        int index = 0;
        for (Source source: contest.getSourcesList()) {
            System.out.println("(from "+source.getLocationDir().getAbsolutePath()+" directory, enabled: "+source.isEnabled()+")");
            boolean printed = false;
            for (Competitor competitor : fsWorker.listCompetitors(source.getLocationDir())) {
                System.out.printf("%3d %-50s\n", (++index), competitor.getName());
                printed = true;
            }
            if (printed==false){
                System.out.println("    <empty>");
            }
        }
        System.out.println("Total "+index+" competitors.");
        return ImmutableList.copyOf(pendingArgs);
    }
}
